{
 "metadata": {
  "name": "qubits"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from sympy import symbols\n",
      "from sympy.core.trace import Tr\n",
      "from sympy.matrices.matrices import Matrix\n",
      "from IPython.core.display import display_pretty\n",
      "from sympy.printing.latex import *\n",
      "from sympy.physics.quantum.cartesian import *\n",
      "from sympy.physics.quantum.qubit import *\n",
      "from sympy.physics.quantum.density import *\n",
      "\n",
      "%load_ext sympyprinting\n",
      "\n",
      "#TODO: Add examples of simple qubit usage "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 4
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## Examples of Tr operations on Qubits"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "q1 = Qubit('10110')\n",
      "q2 = Qubit('01010')\n",
      "d = Density( [q1, 0.6], [q2, 0.4] )\n",
      "\n",
      "# Trace one bit \n",
      "t = Tr(d,[0])\n",
      "\n",
      "display_pretty(t.doit())\n",
      "\n",
      "\n",
      "# Partial trace of 3 qubits\n",
      "# the 0th bit is the right-most bit\n",
      "t = Tr(d,[2, 1, 3])\n",
      "display_pretty(t.doit())"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "display_data",
       "text": [
        "0.4\u22c5(\u27580101\u27e9, 1) + 0.6\u22c5(\u27581011\u27e9, 1)"
       ]
      },
      {
       "output_type": "display_data",
       "text": [
        "0.4\u22c5(\u275800\u27e9, 1) + 0.6\u22c5(\u275810\u27e9, 1)"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## Partial Tr of mixed state"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from sympy import *\n",
      "q = (1/sqrt(2)) * (Qubit('00') + Qubit('11'))\n",
      "\n",
      "d = Density ( [q, 1.0] )\n",
      "t = Tr(d, [0])\n",
      "display_pretty(t.doit())"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "display_data",
       "text": [
        "0.5\u22c5(\u27580\u27e9, 1) + 0.5\u22c5(\u27581\u27e9, 1)"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 3
    }
   ],
   "metadata": {}
  }
 ]
}